<?php
/**
 * Created by Command.
 * User: Vito
 */

declare (strict_types = 1);

namespace app\model;
use app\model\traits\TreeTrait;
class PollingType extends BaseModel
{
    use TreeTrait;
    /**
     * @Description: 添加巡检内容
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $data
     * @Date: 2022-11-03 09:15:41
     * @version: 1.0.0
     * @return [type]
     */    
    public function addContent($data){
        return self::create($data);
    }

    /**
     * @Description: 获取详情
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $where
     * @Date: 2022-11-03 10:15:54
     * @version: 1.0.0
     * @return [type]
     */    
    public static function getPollingType($where,$value = null){
        if($value){
            return self::withoutGlobalScope(['pid'])->where($where)->column($value);
        }else{
            return self::withoutGlobalScope(['pid'])->where($where)->select();
        }
        
    }

    /**
     * @Description: 修改巡检类型和内容
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $where
     * @param [type] $data
     * @Date: 2022-11-03 10:53:51
     * @version: 1.0.0
     * @return [type]
     */    
    public static function savePollingType($where,$data){
        return self::withoutGlobalScope(['pid'])->where($where)->update($data);
    }
    /**
     * @Description: 删除巡检内容
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $where
     * @Date: 2022-11-03 10:59:37
     * @version: 1.0.0
     * @return [type]
     */
    public static function deletePollingType($where){
        // $pollingType = new PollingType;
        // return $pollingType->where('id', 34)->delete();
       
        $res = self::withoutGlobalScope(['pid'])->where($where)->useSoftDelete('delete_time', time())->delete();

        return $res;
      
        // return self::destroy(10);
        // return   self::destroy(function ($query) {
        //     $query->where($where);
        // });

    }
    /**
     * @Description: 获取全部巡检分类
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-11-04 09:32:22
     * @version: 1.0.0
     * @return [type]
     */
    public static function getType(){
        return self::select();
    }

    /**
     * 全局查询范围
     * @var string[]
     */
    protected $globalScope = ['pid'];
    public function scopePid($query)
    {
        $query->where('pid', 0);
    }
}
